<?php
include 'seguranca.php';
include 'Model/Usuario.php';
include 'Model/DAO/UsuarioDAO.php';
protegePagina();

$usuarioDAO = new UsuarioDAO();
if (isset($_POST['edtUsuario'])) 
{
    $usuario = new Usuario();
    $usuario->setIdUsuario($_GET['IDUsuario']);
    $usuario->setNomeUsuario($_POST['nome']);
    $usuario->setUsuario($_POST['usuario']);
    $usuario->setSenhaUsuario(md5($_POST['senha']));
    $usuario->setEmailUsuario($_POST['email']);
    $usuarioDAO->updateUsuario($usuario);

    if ($usuarioDAO) 
    {
      echo 'Registro alterado com sucesso';
      header('Location: usuario_list.php');
    } 
    else 
    {
      echo 'Não foi possivel alterar o registro,tente novamente';
      header('Location: usuario_edit.php');
    }
}
$showUsuario = $usuarioDAO->getByIDUsuario($_GET['IDUsuario']);
?>
<!DOCTYPE html PUBLIC '-//W3C//DTD XHTML 1.0 Strict//EN' 'http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd'>
<html xmlns='http://www.w3.org/1999/xhtml' xml:lang='pt-br' lang='pt-br'>
    <head>
        <meta http-equiv='content-type' content='text/html; charset=utf-8' />
        <meta http-equiv='content-language' content='pt-br' />
        <meta name='robots' content='noindex,nofollow' />
        <link rel='stylesheet' media='screen,projection' type='text/css' href='css/reset.css' /> <!-- RESET -->
        <link rel='stylesheet' media='screen,projection' type='text/css' href='css/main.css' /> <!-- MAIN STYLE SHEET -->
        <link rel='stylesheet' media='screen,projection' type='text/css' href='css/2col.css' title='2col' /> <!-- DEFAULT: 2 COLUMNS -->
        <link rel='alternate stylesheet' media='screen,projection' type='text/css' href='css/1col.css' title='1col' /> <!-- ALTERNATE: 1 COLUMN -->
        <!--[if lte IE 6]><link rel='stylesheet' media='screen,projection' type='text/css' href='css/main-ie6.css' /><![endif]--> <!-- MSIE6 -->
        <link rel='stylesheet' media='screen,projection' type='text/css' href='css/style.css' /> <!-- GRAPHIC THEME -->
        <link rel='stylesheet' media='screen,projection' type='text/css' href='css/mystyle.css' /> <!-- WRITE YOUR CSS CODE HERE -->
        <script type='text/javascript' src='js/jquery.js'></script>
        <script type='text/javascript' src='js/jquery.switcher.js'></script>
        <script type='text/javascript' src='js/jquery.validate.js'></script>
        <script type='text/javascript' src='js/toggle.js'></script>
        <title>Usuário</title>
    </head>
    <body>
        <div id='main'>
<?php include 'includes/inc_header.php' ?>
            <hr class='noscreen' />
<?php include 'includes/inc_menu.php' ?>
            <hr class='noscreen' />
            <div id='cols' class='box'>
<?php include 'includes/left-column.php' ?>
            </div>
            <hr class='noscreen' />

            <!-- Content (Right Column) -->
            <div id='content' class='box'>
                <h1>Cadastro de Usuários</h1>
                <p class='msg info' id='resposta'></p>
                <p class='msg error' id='error'></p>
                <form action='<?php $_SERVER['PHP_SELF']; ?>' method='post' id='formUser'>
                    <fieldset>
                        <legend></legend>
                        <p class='nomt'>
                            <label for='nome' class='req'>Nome:</label><br />
                            <input type='text'
                                   name='nome'
                                   class='input-text required'
                                   id='nome'
                                   size='60' 
                                   value='<?= $showUsuario->getNomeUsuario(); ?>'   />
                        </p>
                        <p class='nomt'>
                            <label for='usuario' class='req'>Usuário:</label><br />
                            <input type='text' 
                                   name='usuario'
                                   class='input-text required'
                                   id='usuario'
                                   size='60'
                                   value='<?= $showUsuario->getUsuario(); ?>'
                                   />
                        </p>
                        <p class='nomt'>
                            <label for='email' class='req'>Email:</label><br />
                            <input type='text' 
                                   name='email'
                                   class='input-text required'
                                   id='email'
                                   size='60'
                                   value='<?= $showUsuario->getEmailUsuario(); ?>' />
                        </p>
                        <p class='nomt'>
                            <label for='senha' class='req'>Senha:</label><br />
                            <input type='password' 
                                   name='senha'
                                   class='input-text required'
                                   id='senha'
                                   size='60'
                                   value='<?= $showUsuario->getSenhaUsuario(); ?>'/>
                        </p>
                        <p class='nomt'>
                            <label for='conf_senha' class='req'>Confirmar Senha:</label><br />
                            <input type='password' 
                                   name='conf_senha'
                                   class='input-text required'
                                   id='conf_senha'
                                   size='60'   />
                        </p>
                        <p><input type='submit' name='edtUsuario' value='Enviar' /></p>
                    </fieldset>
                </form>
            </div> <!-- /content -->
        </div> <!-- /cols -->
        <hr class='noscreen' />
        <!-- Footer -->
<?php include 'includes/inc_footer.php' ?>
        <!-- /footer -->